I tried triggering a lambda to create and send a message into SQS when an event occurs in S3 bucket

I tried triggering a lambda to create and send a message into SQS when an event occurs in S3 bucket

Clock Icon2023.04.30

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Introduction

Hemanth of Alliance Department here. In this blog, I tried triggering a lambda to create and send a message into SQS when an event occurs in the S3 bucket.

AWS

Is a secure cloud service platform that offers compute power, database storage, content delivery, network, and other functionality to help businesses scale and grow. It is one of the first cloud vendors to start services in the year 2006. It offers all the 3 service models namely IAAS, PAAS, and SAAS. Some of the notable domains in AWS are Compute, Migration, Storage, Network and Content Delivery, Management Tools, Database, Messaging, Security and Identity Compliance, and many more.

AWS lambda

A Serverless compute service that runs code as a reply to events and automatically takes care of the bottom resources. It runs code on high availability compute infrastructure and performs all the administration of the compute resources.

S3

Simple and popular AWS Service for storage. Replicates data by default across multiple facilities. It charges per usage. It is deeply integrated with AWS Services. Buckets are logical storage units. The Objects are data added to the bucket. S3 has a storage class on object level which can save money by moving less frequently accessed objects to a colder storage class.

SQS

It is a web service that enables message exchange between software components at any volume without message loss or the need for additional services to be accessible. It contains standard building blocks like cost allocation tags and dead-letter queues and offers a general web services API that may be used through any programming language that the AWS SDK supports.

Demo

In the AWS Console go to AWS Lambda and click on create function Give a function name, change the runtime as below, and click on create function Writing down the following code and click on deploy Now changing some settings, in configuration click on permissions click on add permissions and click on attach policies Search for SQS, click on SQSFullAccess, and click on add permissions Now going back to lambda and clicking on Test, give a name make the following changes and click on save Now click on test and you'll get the following execution result Checking SQS and Queue is successfully created
Deleting the SQS queue now Creating an S3 bucket Going back to lambda and click add trigger select S3 as source and choose the bucket created above check the acknowledgment message and press Add button Uploading objects in S3 successfully uploaded Refreshing SQS and you can see that a new queue was created as object was uploaded into S3 clicking on send and receive message Now poll for messages Checking the body and attributes

Conclusion

I hope with this you have an understanding of how triggering a lambda can create and send a message into SQS when an event takes place in S3 bucket.

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.